package org.grow.webchat.chat;

import org.grow.webchat.chat.entity.ChatRequest;
import org.grow.webchat.chat.entity.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.*;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.annotation.SubscribeMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.time.LocalDateTime;
import java.util.Map;

@Controller
public class ChatController {
    @Autowired
    SimpMessagingTemplate messagingTemplate;

    @MessageMapping("/msgController/{roomCode}")
    public void chat(@DestinationVariable String roomCode,
                     @Payload ChatRequest chatRequest){
        System.out.println("room code : "+roomCode);
        System.out.println(chatRequest.getCore());
        ChatResponse chatResponse = new ChatResponse();
        chatResponse.setDateTime(LocalDateTime.now());
        chatResponse.setCore(chatRequest.getCore()+"666");
        messagingTemplate.convertAndSend(
                ChatBrokerConfig.BrokerTitle+"/"+roomCode,chatResponse);
    }
//    @SubscribeMapping("/msgHttp")
//    public chat(@Payload ChatRequest chatRequest){
//
//    }

}
